#include "base_darr.hpp"

template <class T>
void base_darr<T>::reset() {}

template <class T>
base_darr<T>::base_darr() {}

template <class T>
bool base_darr<T>::allocate_arr( base_darr &ref, size_type size ) {
  // TODO: allocate array memory by size
  bool result = false;
  return result;
}

template <class T>
void base_darr<T>::release_arr( base_darr &ref, size_type size ) {
  // TODO: release array element from head
}

template <class T>
base_darr<T>::base_darr_allocator::base_darr_allocator() : _size( 0 ) {
  if ( _heap_mem == nullptr ) _heap_mem = new value_type[DEFAULT_CAPACITY];
}

template <class T>
base_darr<T>::base_darr_allocator::~base_darr_allocator() {
  if ( _heap_mem ) delete[] _heap_mem;
  _size = 0;
  _head_mem = nullptr;
}

template <class T>
void base_darr<T>::base_darr_allocator::_base_expand( size_type capacity ) {
  // if allocate capacity >= current capacity / 2
  if ( capacity >= _base_capacity / 2 ) {
    // then allocate a new array
    pointer_type old = _heap_mem;
    _heap_mem = new value_type[_base_capacity * 2];
    for ( size_type i = 0; i < capacity; i++ ) {
      // copy content from old array to the new array
      _heap_mem[i] = old[i];
    }
    delete[] old;
  }
}


template <class T>
base_darr<T>::const_pointer_type
base_darr<T>::base_darr_allocator::_allocate( size_type capacity ) {
  // TODO: allocate sequence memory
  _base_expand(capacity);
  
}

template <class T>
void base_darr<T>::base_darr_allocator::_deallocate( const_pointer_type head,
                                                     size_type capacity ) {
  // TODO: deallocate sequence memory
}
